package entities;

import view.ChessBoard;

import java.awt.*;
import java.util.List;
import java.util.Map;
import java.util.Set;

/***
 * Author: Mr.Zheng, Time: 2018/5/6/9:24
 * Description: 卒/兵
 */
public class Zu extends BasePiece {

    public Zu(int x, int y, Color color) {
        super(x, y, color);
        //判断是卒还是兵
        if (color == BasePiece.BLACK_PIECE) {
            this.pieceName = "卒";
        } else {
            this.pieceName = "兵";
        }
    }


    @Override
    public void updateAvailablePoints(Map<Point, BasePiece> pointPieceMap) {
        availablePoints.clear();
        int x = getPosition().x;
        int y = getPosition().y;

        //无论小卒有没有过河都可以一直向前且不能后退
        for (int yi = y - 1; yi >= 0; yi--) {
            BasePiece piece1 = pointPieceMap.get(new Point(x, yi));
            //当点为空或者为敌方棋子时，添加该点
            if (piece1 == null || piece1.getColor() != this.getColor()) {
                this.availablePoints.add(new AvailablePoint(x, yi));
            }
            break;
        }
        //当小卒过河后取它左右两个点
        if (y <= 4) {
            BasePiece piece2 = pointPieceMap.get(new Point(x - 1, y));
            BasePiece piece3 = pointPieceMap.get(new Point(x + 1, y));
            if (piece2 == null || piece2.getColor() != this.getColor()) {
                this.availablePoints.add(new AvailablePoint(x - 1, y));
            }
            if (piece3 == null || piece3.getColor() != this.getColor()) {
                this.availablePoints.add(new AvailablePoint(x + 1, y));
            }
        }

    }
}
